<template>
  <basic-form
      style="marginTop:20px"
      ref="forms"
      :isBtn="false"
      :formInfos="s_FormInfo"
      :formDatas="s_formDatas"
      :rules="s_rules"
      :buttonText="['','','']"
      :btnCusStyle="{ boxShadow: 'none' }"
      :isInline="true"
      @onSubmit="onSubmit"
      @onChangeType="onChangeType"
  ></basic-form>
</template>

<script>
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListInfo from '@/views/app/biz/common/aListInfo'
import aListTable from '@/views/app/biz/common/aListTable'
import basicForm from '../common/basicForm'
import {
  getDetailByConditions,
  getDetailByConditionsCount,
} from '../saleOrder/saleOrder'
import {
  s_FormInfo,s_formDatas,s_rules
} from './mergeStepConfig'


export default {
  components: {
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListInfo,
    aListTable,
    basicForm,
  },
  data() {
    return {
      s_FormInfo: s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules,
    }
  },
  computed: {},

  mounted(){
    
  },
  methods: {
    reset(){
    },
    onValidate(val){
        this.$refs.forms.submitForm()
        
    },
    onSubmit(val){
      this.$emit('onSubmitForm',val)
    },
    setformDatas(details){
      console.log(details[0].child[0]);
      if (details[0].child[0].deliveryAddr) {
        this.s_formDatas.receiver=details[0].child[0].delivery
        this.s_formDatas.receiverTel=details[0].child[0].deliveryTel
        this.s_formDatas.receiverAddr=details[0].child[0].deliveryAddr
      }else{
        let itemIndex=this.s_FormInfo.findIndex((item)=>{
          return item.name=='receiverAddr'
        })
        let formInfo=[...this.s_FormInfo]
        formInfo[itemIndex]={ label: '收件地址', name: 'receiverAddr', type: 'deliveryAddressSelect', placeholder: '请选择收件地址' }
        this.s_FormInfo=formInfo
      }
      
    },
    // 搜索栏选择下拉select触发搜索val[0]表示选中的record中的pid,val[1]表示选中的record全部信息
    onChangeType(name, val) {
      console.log('formName',name)
      console.log('val',val)
      this.s_formDatas=this.$refs.forms.form
      switch (name) {
        case 'senderAddr': 
          if (!val[0]) {
            this.s_formDatas.senderAddr =null
            this.s_formDatas.sender =null
            this.s_formDatas.senderTel =null
          }else{
            this.s_formDatas.senderAddr =val[1].addr
            this.s_formDatas.sender =val[1].contact
            this.s_formDatas.senderTel =val[1].contactTel
          }
        break 
        case 'receiverAddr': 
          if (!val[0]) {
            this.s_formDatas.receiverAddr =null
            this.s_formDatas.receiver =null
            this.s_formDatas.receiverTel =null
          }else{
            this.s_formDatas.receiverAddr =val[1].addr
            this.s_formDatas.receiver =val[1].contact
            this.s_formDatas.receiverTel =val[1].contactTel
          }
        break
      }
    },
  },
}
</script>

<style>
</style>